const request = require("../../../../utils/request.js")
Page({
  data: {
    // tab切换    
    currentTab: 0,
    scrollHeight: 0,
    storeId: -1,
    cate_data: [{
        id: 1,
        subtitle: "cate1",
        pic: "/images/sample_cate/1.jpeg"
      },
      {
        id: 2,
        subtitle: "cate2",
        pic: "/images/sample_cate/2.jpeg"
      },
      {
        id: 3,
        subtitle: "cate3",
        pic: "/images/sample_cate/3.jpeg"
      },
      {
        id: 4,
        subtitle: "cate4",
        pic: "/images/sample_cate/4.jpeg"
      },
      {
        id: 5,
        subtitle: "cate5",
        pic: "/images/sample_cate/5.jpeg"
      },
      {
        id: 6,
        subtitle: "cate6",
        pic: "/images/sample_cate/6.jpeg"
      },
      {
        id: 7,
        subtitle: "cate7",
        pic: "/images/sample_cate/7.jpeg"
      },
      {
        id: 8,
        subtitle: "cate8",
        pic: "/images/sample_cate/8.jpeg"
      },
      {
        id: 9,
        subtitle: "cate9",
        pic: "/images/sample_cate/9.jpeg"
      },
      {
        id: 10,
        subtitle: "cate10",
        pic: "/images/sample_cate/10.jpeg"
      }
    ],
    leftCol: [],
    rightCol: []
  },
  swichNav: function(e) {

    var that = this;
    if (that.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
      })
    }
  },
  swiperChange: function(e) {

    this.setData({
      currentTab: e.detail.current,
    })
  },
  setCol: function() {
    var that = this;
    let leftCol = that.data.leftCol;
    let rightCol = that.data.rightCol;
    var data = that.data.cate_data;
    console.log(data);
    for (var i = 0; i < data.length; i++) {
      if (data[i].id % 2 != 0) {
        leftCol.push(data[i]);
      } else {
        rightCol.push(data[i]);
      }
    }
    console.log(leftCol);
    console.log(rightCol);
    that.setData({
      leftCol: leftCol,
      rightCol: rightCol
    })
  },
  onLoad: function(options) {
    var that = this;
    var storeId = options.storeId;
    var storeName = options.storeName;
    that.setData({
      storeId: storeId
    })
    wx.setNavigationBarTitle({
      title: "商品分类——" + storeName,
    })
    // 生命周期函数--监听页面加载  
    this.setCol();
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        console.info(res.windowHeight);
        that.setData({
          scrollHeight: res.windowHeight
        });
      },
    });
  },
  onReady: function() {
    // 生命周期函数--监听页面初次渲染完成  
  },
  onShow: function() {
    // 生命周期函数--监听页面显示  
  },
  onHide: function() {
    // 生命周期函数--监听页面隐藏  
  },
  onUnload: function() {
    // 生命周期函数--监听页面卸载  
  },
  onPullDownRefresh: function() {
    // 页面相关事件处理函数--监听用户下拉动作  
  },
  onReachBottom: function() {
    // 页面上拉触底事件的处理函数  
  },
  onShareAppMessage: function() {
    // 用户点击右上角分享  
    return {
      title: 'title', // 分享标题  
      desc: 'desc', // 分享描述  
      path: 'path' // 分享路径  
    }
  },

  accessCate: function(e) {
    console.log(e.currentTarget.id);
    var that = this;
    var categoryId = e.currentTarget.id;
    var storeId = that.data.storeId;
    //categoryId 暂时用1
    categoryId = 1;
    //**************
    wx.navigateTo({
      url: '/pages/search_results/search_results' + '?categoryId=' + categoryId + '&storeId=' + storeId,
    })
  }
})